package top.goldenyear.porpoise.framework.security.core.service;

import cn.hutool.v7.crypto.digest.BCrypt;

/**
 * @author airhead
 */
public class BcryptPasswordEncoder {
  // BCrypt.GENSALT_DEFAULT_LOG2_ROUNDS
  private int rounds = 10;

  public BcryptPasswordEncoder() {}

  public BcryptPasswordEncoder(int rounds) {
    this.rounds = rounds;
  }

  public String encode(String rawPassword) {
    return BCrypt.hashpw(rawPassword, BCrypt.gensalt(rounds));
  }

  public boolean matches(String rawPassword, String encodedPassword){
    return BCrypt.checkpw(rawPassword, encodedPassword);
  }
}
